<template>
	<view class="container">
		<uni-forms ref="form" :rules="{}">
			<uni-forms-item label="" name="">
				<uni-easyinput v-model="user.telephone" placeholder="请输入手机号" />
			</uni-forms-item>
			<uni-forms-item label="" name="">
				<uni-easyinput type="password" v-model="user.password" placeholder="请输入密码" />
			</uni-forms-item>
			<uni-forms-item label="" name="">
				<button type="primary" @click="login">登录</button>
			</uni-forms-item>
		</uni-forms>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {
					telephone: '12345678901',
					password: '123'
				}
			}
		},
		methods: {
			login(e) {
						uni.request({
							url: 'http://localhost:8090/foodapp/user/login',
							method: 'POST',
							data: this.user,
							success: res => {
								if (res.data.success) {
									
									uni.setStorageSync('userInfo', res.data.data)
									uni.showToast({
										title: '' + res.data.data.username,
										icon: 'none'
									});
									uni.switchTab({
										url:'../home/home'
									})
								} else {
									uni.removeStorageSync('userInfo')
									uni.showToast({
										title: '失败',
										icon: 'none'
									});
								}
			
			
							},
							fail: () => {},
							complete: () => {}
						});
					}
				},
				onLoad: () => {
					uni.onTabBarMidButtonTap(function(e) {
						console.log(e)
			
					})
				}
			}
</script>

<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
	}
</style>
